package com.lw.algorithm.heap;

import com.lw.algorithm.service.CalTimeService;
import com.lw.algorithm.utils.CalTimeUtils;

public class TestMaxHeap implements CalTimeService{
	
	public static int[] getArray(int length){
		int[] arr = new int[length];
		for( int i = 0;i < length;i++){
			arr[i] = length - i;
		}
		return arr;
	}
	public static void main(String[] args) {
		int[] arr = getArray(100000000);
		CalTimeUtils.excute(new TestMaxHeap(), arr);
		
	}
	public void excute(int[] arr) {
		MaxHeap maxHeap = new MaxHeap(200);
		for(int i = 0;i < arr.length;i++){
			int temp = arr[i];
			if(maxHeap.getCount() < 200){
				maxHeap.put(temp);
			}else  {
				if(temp > maxHeap.getMaxValue()){
					continue;
				}else {
					maxHeap.popMax();
					maxHeap.put(temp);
				}
			}
		}
		int count = maxHeap.getCount();
		for(int k = 0;k < count;k++){
			System.out.println(maxHeap.popMax());
		}
	}
}
